
"""
    cookie 保持浏览器和服务器交互的状态的，保存在浏览器
    cookie的设置和获取
        设置cookie：response.set_cookie(key,value,max_age)
            max_age表示cookie在浏览器的储存时间，单位是秒
        获取cookie：request.cookies.get("key")
"""

from flask import Flask, make_response, request

app = Flask(__name__)


# 设置cookie
@app.route("/set_cookie")
def set_cookie():

    # 调用make_response方法获取响应体对象，函数传参响应体
    resp = make_response("set cookie")

    resp.set_cookie("language", "python")
    resp.set_cookie("time", "2021", 5)

    return resp


# 获取cookie
@app.route("/get_cookie")
def get_cookie():
    value1 = request.cookies.get("language")
    value2 = request.cookies.get("time")

    return "language is %s, time is %s" % (value1, value2)


if __name__ == '__main__':
    app.run(debug=True)

